<?
$_id_gallery	= D_GALLERY_DATA;

if ($DATA['component']['id'] && ($g = (int)param('gallery'))) {

	$s = array_extend( array('path' => 'album', 'tn' => FP_TN_DIR, 'w' => 800, 'h' => 600, 'tnw' => 96, 'tnh' => 96, 'gw' => 96, 'gh' => 96, 'caption' => '', 'gparam' => 'gallery', 'param' => 'id'), $DATA['component']['settings']);

	$s['path'] = createdir(FP_UPLOAD_PATH."$s[path]/$g/");
	createdir($s['path'].$s['tn']);


	if ($d = param('delete')) {	// *** delete photo
	
		if ((strpos($d, '..') === false) && is_file($_SERVER['DOCUMENT_ROOT'].$s['path'].$d)) {
			@unlink($_SERVER['DOCUMENT_ROOT'].$s['path'].$d);
			@unlink($_SERVER['DOCUMENT_ROOT'].$s['path'].$s['tn'].$d);
			
			dataset('db_delete', tb('data'), "id_data=$_id_gallery AND assoc=\"".h($s['path'])."\" AND name=\"".h($a)."\"");
		}
	
		header("Location: "._transformURL($CURRENT->url, array('remove_param' => 'delete')));
		exit;
	}


	$DATA['gallery'] = datafetch_array('gallery2', $s['path']);	// load existing images list
	uksort($DATA['gallery'], 'fn_numeric_compare');
	
	switch (action(array('photo_add'))) {
	
		case 'photo_add':
	
				if ($temp = takeImage('image', $s['w'], $s['h'], $s['path'], $s['tnw'], $s['tnh'], $s['path'].$s['tn']))
						$DATA['gallery'][$temp['filename']] = array('w' => $temp['w'], 'h' => $temp['h'], 'fn' => $temp['filename'], 'tn' => $s['tn'].$temp['filename']);
						
				return false;
	}


	return false;

} else exit;

?>